package com.jdpc.weparty.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import com.jdpc.weparty.service.user.UserInfo
import java.util.*
import javax.persistence.*
import kotlin.collections.HashSet


@Entity
@Table(name = "tb_user")
public class User {
    fun setUserInfo(userInfo: UserInfo) {
        userInfo.let {
            this.age = it.age
            this.phoneNumber = it.phoneNumber
            this.gender = it.gender
            this.userName = it.userName
            this.userNumber = it.userNumber
            this.avatar = it.avatar
        }
    }

    //微信账号 的唯一标识
    @JsonIgnore
    @Column(name = "wx_openid")
    var wxOpenId = ""

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Int = -1

    //手机号 账号
    @Column(name = "phone_number")
    var phoneNumber: String = ""

    //密码
    @Column(name = "pwd")
    var password: String = ""

    //用户名 昵称
    @Column(name = "user_name")
    var userName: String = ""

    //用户学号、老师工号
    @Column(name = "user_number")
    var userNumber: String = ""

    //以下为用户选填信息
    @Column(name = "user_gender")
    var gender: String = ""

    @Column(name = "user_age")
    var age = -1

    @Column(name = "avatar")
    var avatar = ""

    //最后修改密码日期
    @JsonIgnore
    var lastPasswordResetDate: Date = Date()

    @OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER)
    @JsonIgnore
    @JoinColumn(name = "user_id")
    var myUdr: Set<Udr>? = HashSet()

    //....其他信息略


    //管理员要审核的活动
    @JsonIgnore
    @OneToMany(mappedBy = "examiner", fetch = FetchType.EAGER)
    var examinedActivities: MutableSet<Activity> = HashSet<Activity>()

    //发起的活动
    @JsonIgnore
    @OneToMany(mappedBy = "publisher", fetch = FetchType.EAGER)
    var publishedActivities: MutableSet<Activity> = HashSet<Activity>()

    override fun toString(): String {
        return "User(id=$id, userName='$userName', age='$age')"
    }

}